package com.hdaccp.xingmu.controller;

import com.hdaccp.xingmu.dao.HuxingDao;
import com.hdaccp.xingmu.entity.Huxing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
@RequestMapping("/huxing")
public class HuxingCon {
    @Autowired
    private HuxingDao huxingDao;
    @RequestMapping("/qb")
    public String chaxun(){
        return "WEB-INF/jsp/xiugai";
    }

    @RequestMapping("/hx")
    @ResponseBody
    public List<Huxing> list(){
        return huxingDao.findAll();
    }

    @RequestMapping("/add")
    @ResponseBody
    public List<Huxing> add(Huxing huxing)throws UnsupportedEncodingException {
        huxingDao.save(huxing);
        return  huxingDao.findAll();
    }

    @RequestMapping("/upd")
    @ResponseBody
    public List<Huxing> upd(Huxing huxing)throws UnsupportedEncodingException{
        huxingDao.save(huxing);
        return  huxingDao.findAll();
    }

    @RequestMapping("/del")
    @ResponseBody
    public List<Huxing> del(Long id){
        huxingDao.deleteById(id);
        return huxingDao.findAll();
    }
}
